package com.doit.demo04;

import java.util.*;

public class Test_Set {
    public static void main(String[] args) {
        Set<String> set = new HashSet<>();

//        set = new HashSet<>();//可添加null值        (无序)
//        set = new TreeSet<>();//不允许添加null值       (排序)(降序)
//        set = new LinkedHashSet<>();//可添加null值  (有序)

        set = new TreeSet<>(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o2.compareTo(o1);
            }
        });
        set.add("段哥哥");
        set.add("2021");
        set.add("521");
        set.add("段哥哥");
        set.add("2019");
//        set.add(null);
        System.out.println(set);
        Iterator<String> it = set.iterator();
        while(it.hasNext())
        {
            String s = it.next();
            System.out.println(s);
        }
    }
}
